package com.xctech.yace.main;

import com.google.common.collect.Lists;
import com.xctech.yace.pojo.FileCompareRes;
import com.xctech.yace.util.DirUtil;
import com.xctech.yace.util.ExcelUtil;

import java.io.File;
import java.util.List;
import java.util.Scanner;

/**
 * O32升级脚本通过表名筛选出表结构变化
 */
public class FileCompare {


    public static boolean fileFilter(File file, String pathRes, String[] tables) throws Exception {
        String version = file.getName().substring(0,file.getName().lastIndexOf("."));
        Scanner sc = new Scanner(file);
        sc.useDelimiter("/"); //分隔符
        List<FileCompareRes> list = Lists.newArrayList();
        while (sc.hasNext()) {
            String str = sc.nextLine().toLowerCase();
            for (String table : tables) {
                if (str.contains(table.toLowerCase()) && (str.contains("alter"))) {
                    list.add(new FileCompareRes(table, version, str));
                }
            }
        }
        String[] title = {"表名","版本","修改内容"};
        ExcelUtil.writeFileRes(title,pathRes,list);
//        EasyExcel.write(pathRes != null ? pathRes : fileRes, FileCompareRes.class).sheet().doWrite(list);
        return true;
    }

//    public static void main(String[] args) throws Exception {
//        fileFilter();
//    }


}
